package com.sakura.mall.member.integrationChangeHistory.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.member.integrationChangeHistory.domain.request.AddIntegrationChangeHistoryRequest;
import com.sakura.mall.member.integrationChangeHistory.domain.request.UpdateIntegrationChangeHistoryRequest;
import com.sakura.mall.member.integrationChangeHistory.domain.request.IntegrationChangeHistoryPageRequest;
import com.sakura.mall.member.integrationChangeHistory.service.IntegrationChangeHistoryService;
import com.sakura.mall.member.integrationChangeHistory.domain.vo.IntegrationChangeHistoryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 积分变化历史记录
 *
 * @author sakura
 */
@RestController
@RequestMapping("/integrationChangeHistory")
@RequiredArgsConstructor
public class IntegrationChangeHistoryController {

    private final IntegrationChangeHistoryService integrationChangeHistoryService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddIntegrationChangeHistoryRequest request) {
        integrationChangeHistoryService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<IntegrationChangeHistoryVo>}
     */
    @GetMapping("list")
    public R<Page<IntegrationChangeHistoryVo>> page(IntegrationChangeHistoryPageRequest request) {
        Page<IntegrationChangeHistoryVo> ret = integrationChangeHistoryService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        integrationChangeHistoryService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateIntegrationChangeHistoryRequest request) {
        integrationChangeHistoryService.updateById(id, request);
        return R.ok();
    }

}
